#include "stm32f10x.h"                  // Device header
#include "OLED.h"
#include "motor.h"
#include "Delay.h"
#include "Serial.h"
#include <string.h>
#include <stdlib.h>


int main(void)
{
	OLED_Init();
	Serial_Init();
	Motor_Init();
	
	Serial_SendString("Start\r\n");
	OLED_ShowString(1, 1, "Speed:");
	OLED_ShowSignedNum(1, 7, 0, 2);
	
	while(1) {
		if (Serial_RxFlag == 1) {
			int8_t speed = atoi(&(Serial_RxPacket[1]));
			if (Serial_RxPacket[0] == '1') {
				speed = -speed;
			}
			Motor_SetSpeed(speed);
			OLED_ShowSignedNum(1, 7, speed, 2);
			Serial_SendString("OK\r\n");
			Serial_RxFlag = 0;
		}
	}
}
